﻿<!DOCTYPE html>
<html>
    <head>
        <title>View Log Files</title>
    </head>
    <body>
    <form action="" method="get">
    @{
        Settings.LogEmailSubscribers    subscriberBlock = null;
        string productTitle = null;
        if(Request.Params["product"]==null)
        {
            subscriberBlock = Settings.LogSubscribers;
            productTitle = "System";
        }
        else
        {
            Settings.Product product = new Settings.Product(Request.Params["product"]);
            subscriberBlock = product.LogSubscribers;
            productTitle = @product.Name;
            <input type="hidden" name="product" value="@product.Name" />
        }
    }
    <table>
        <tr><td colspan="4"><h2>@productTitle
        @{
            if (Request.Params["submit"] != null)
            {
                if (Request.Params["submit"] == "Save")
                {
                    // Now save the log reporting settings.
                    subscriberBlock.Clear();
                    for (int i = 0; i < 1000; ++i)
                    {
                        var email = Request.Params["email" + i.ToString()];
                        if (!String.IsNullOrEmpty(email))
                        {
                            subscriberBlock.Add(email, (Request.Params["log" + i.ToString()] != null), (Request.Params["err" + i.ToString()] != null), (Request.Params["dmp" + i.ToString()] != null));
                        }
                    }
                    subscriberBlock.Save();
                    <b>(saved)</b>
                }
                else if (Request.Params["submit"] == "Test")
                {
                    if(Request.Params["product"]==null)
                    {
                        log.Error("This is an Test");
                        log.Warning("This is a Test");
                        log.SendLog();
                    }
                    else
                    {
                        var product = new Settings.Product(Request.Params["product"]);
                        product.WriteLogFile("ERROR: This is an error","err");
                        product.WriteLogFile("ERROR: This is a log", "log");
                        log.SendLog(product.Name);
                    }
                    <b>(Test)</b>
                }
            }
        }
         Log File Subscribers:</h2></td></tr>
            @{
                int j = 0;
                foreach (var subscriber in subscriberBlock.Subscribers)
                {
                <tr><td>Email:</td><td><input type="text" name="@("email" + j.ToString())" value="@subscriber.Email" /></td>
                    <td><input type="checkbox" name="@("log" + j.ToString())" @(subscriber.Logs ? "Checked" : "") /> Log
                    <input type="checkbox" name="@("err" + j.ToString())"  @(subscriber.Errs ? "Checked" : "") /> Errors
                    <input type="checkbox" name="@("dmp" + j.ToString())" @(subscriber.Dmps ? "Checked" : "") /> Dumps</td>
                    <td></td>
                    </tr>
                    ++j;
                }
                <tr><td>Email:</td><td><input type="text" name="@("email" + j.ToString())" value="" /></td>
                    <td><input type="checkbox" name="@("log" + j.ToString())" />
                    Log<input type="checkbox" name="@("err" + j.ToString())"  /> Errors<input type="checkbox" name="@("dmp" + j.ToString())" /> Dumps</td>
                    <td></td>
                    </tr>
            }
        <tr><td colspan="2"><input type="submit" name="submit" value="Save" /></td><td colspan="2"><input type="submit" name="submit" value="Test" /></td></tr>
    </table>
    </form>
    </body>
</html>
